package com.yanqu.road.logic.activity.foxcard.game.spell;

import com.yanqu.road.entity.activity.foxcard.FoxBaseCard;
import com.yanqu.road.entity.activity.foxcard.FoxHandCard;
import com.yanqu.road.entity.activity.foxcard.config.FoxCardBuffConfig;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardShowInfo;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardShowType;

import java.util.ArrayList;
import java.util.List;

/**
 * 选定牌给予buff
 * 数量|buffId
 */
public class FoxCardSpellUse1 extends FoxCardSpellUseBase {
    @Override
    protected boolean spellUse(FoxCardGameLogic gameLogic) {
        int num = spellConfig.getParamList().get(0);
        int targetNum = targetIdList.size();
        if (targetNum <= 0 || targetNum > num) {
            return false;
        }

        int buffId = spellConfig.getParamList().get(1);

        FoxCardBuffConfig buffConfig = gameLogic.getConfig().getBuffConfigMap().get(buffId);
        if (buffConfig == null) {
            return false;
        }

        List<FoxBaseCard> triggerCards = new ArrayList<>();
        int showType = 0;
        for (Integer handCardId : targetIdList) {
            FoxHandCard foxHandCard = gameLogic.getGameData().getHandCards().stream().filter(handCard -> handCard.getId() == handCardId).findFirst().orElse(null);
            if (foxHandCard == null) {
                return false;
            }

            if (buffConfig.getSort() == 1) {//增强效果
                foxHandCard.setReinforceEffect(buffId);
                triggerCards.add(foxHandCard);
                showType = eFoxCardShowType.REINFORCE_EFFECT.getValue();
            } else if (buffConfig.getSort() == 2) {//版本效果
                foxHandCard.setVersionEffect(buffId);
                triggerCards.add(foxHandCard);
                showType = eFoxCardShowType.VERSION_EFFECT.getValue();
            } else if (buffConfig.getSort() == 3) { //印章效果
                foxHandCard.setSealEffect(buffId);
                triggerCards.add(foxHandCard);
                showType = eFoxCardShowType.SEAL_EFFECT.getValue();
            } else {
                return false;
            }
        }

        if (triggerCards.isEmpty()) {
            return false;
        }

        FoxCardShowInfo showInfo = gameLogic.newFoxShow(showType);
        showInfo.setTriggerCards(triggerCards);
        showInfo.setShowValue(buffId);

        return true;
    }
}
